package io.renren.modules.sys.controller;

import com.xxl.sso.core.conf.Conf;
import com.xxl.sso.core.user.XxlSsoUser;
import io.renren.modules.sys.shiro.ShiroUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * 结合xxl-sso不用本身的登陆页
 *
 * @author shoufeng
 */
@Controller
public class SsoController extends AbstractController {

    @RequestMapping("/login")
    public String login(HttpServletRequest request, HttpServletResponse responses) {
        XxlSsoUser xxlUser = (XxlSsoUser) request.getAttribute(Conf.SSO_USER);
        Map<String, String> plugininfo = xxlUser.getPlugininfo();
        Subject subject = ShiroUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(plugininfo.get("loginUsername"), plugininfo.get("loginPassword"));
        subject.login(token);
        return "index.html";
    }

}
